'use strict';
const db = uniCloud.database()
const breakfast_food = db.collection('recommend_breakfast_food')
const lunch_food = db.collection('recommend_lunch_food')
const dinner_food = db.collection('recommend_dinner_food')
const add_food = db.collection('recommend_add_food')
exports.main = async (event, context) => {
	//event为客户端上传的参数
	let data;
	if (event.type == 1) {
		data = await breakfast_food.aggregate().sample({
			size: 1
		}).end()
	} else if (event.type == 2) {
		data = await lunch_food.aggregate().sample({
			size: 1
		}).end()
	} else if (event.type == 3) {
		data = await dinner_food.aggregate().sample({
			size: 1
		}).end()
	} else {
		data = await add_food.aggregate().sample({
			size: 1
		}).end()
	}


	//返回数据给客户端
	return {
		code: 200,
		data
	}
};